
#import "SinglePageView.h"

@implementation SinglePageView

- (instancetype)initWithFrame:(CGRect)frame
{
    assert(frame.size.width > 0);
    
    self = [super initWithFrame:frame];
    if (self) {
        self.backgroundColor = [UIColor clearColor];

        const CGSize imageSize = frame.size;
        imageView = [[UIImageView alloc] initWithFrame:CGRectMake((self.bounds.size.width - imageSize.width) / 2, 0, imageSize.width, imageSize.height)];
        imageView.contentMode = UIViewContentModeScaleAspectFit;
        [self addSubview:imageView];
        imageView.autoresizingMask = UIViewAutoresizingFlexibleWidth|UIViewAutoresizingFlexibleHeight;
        
        UITapGestureRecognizer *singleTap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(singleTapRegistered)];
        singleTap.numberOfTapsRequired = 1;
        singleTap.delaysTouchesBegan = NO;
        singleTap.delaysTouchesEnded = NO;
        [self addGestureRecognizer:singleTap];
    }
    
    return self;
}

- (void)singleTapRegistered
{
    [self.delegate didTapOnSinglePageWithIndex:self.index];
}

- (void)setImage:(UIImage*)image
{
    _image = image;
    imageView.image = _image;
}

@end
